Python allows us to assign values to multiple variables in a single statement.
var1,var2,var3.. = value1,value2,value3..
For example: a,b,c = 2,3,4
Multi-Line Statements
Explicit line continuation
In Python, end of a statement is marked by a newline character. But we can make a statement extend over multiple lines with the line continuation character (\).
For example:
S=1+2+3+\
4+5+6+\
7+8+9
Implicit line continuation
This is explicit line continuation. In Python, line continuation is implied inside parentheses ( ), brackets [ ] and braces { }.
We can put multiple statements in a single line using semicolons.
a,b=5,7 ; a,b=b,a ; print(a,b)
Comments
In Python there are two types of comments- Single line comments and multiple lines comments. Single line commenting is commonly used for a brief and quick comment (or to debug a program, we will see it later). On the other hand we use the multiple lines comments to note down something much more in details or to block out an entire chunk of code.
Single line comments
Python single line comment starts with hashtag symbol with no white spaces (#) and lasts till the end of the line.
For example:
# This is a comment
# Print "Welcome !" to console
Multi-line comments
Python multi-line comment is a piece of text enclosed in a delimiter (""") on each end of the comment. Quotes can be single or double
For example:
'''This is a
multi-line comment.
We are printing welcome '''
Type Casting
The process of converting the value of one data type (integer, string, float, etc.) to another data type is called type conversion. Python provides type conversion functions to directly convert one data type to another data type.
Functions
bin(value)
Converts an integer to a binary string.
bool(value)
Converts an argument to a Boolean value
complex(value)
Returns a complex number constructed from arguments.
float(value)
Returns a floating-point object constructed from a number or string.
hex(value)
Converts an integer to a hexadecimal string.
int(value)
Returns an integer object constructed from a number or string.